package fengxici.demo.activemq.spring.service;

import fengxici.demo.activemq.spring.model.User;
import org.springframework.stereotype.Service;
import yihao.jframe4l.lock.annotation.LvLock;
import yihao.jframe4l.lock.annotation.LvLockKey;

/**
 * Created by Fengxici on 2018/1/31.
 */
@Service
public class LockService {


    @LvLock(waitTime = Long.MAX_VALUE, leaseTime = 1)
    public String getValue(String param) throws Exception {
        if ("sleep".equals(param)) {//线程休眠或者断点阻塞，达到一直占用锁的测试效果
            Thread.sleep(1000 * 3);
        }
        return "success";
    }

    @LvLock(keys = {"#userId"})
    public String getValue(String userId, @LvLockKey int id) throws Exception {
        Thread.sleep(60 * 1000);
        return "success";
    }

    @LvLock(keys = {"#user.name", "#user.id"})
    public String getValue(User user) throws Exception {
        Thread.sleep(60 * 1000);
        return "success";
    }

}
